package org.springcloud.wisdom.spring_02_classroom.admin.manageteacher.dao;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springcloud.wisdom.spring_02_classroom.teacher.tschedule.entity.Teacher;

import java.util.List;

@Mapper
public interface ManageTeacherDao {
    //管理员可以通过教师编号重置教师登录密码
    @Update("UPDATE teacher " +
            "SET  tpass=#{tpass} " +
            "WHERE tid=#{tid}")
    int updateTeacherPassword(Teacher teacher);

    //基于课模糊查询教师编号和姓名的分页查看所有教师信息
    @Select("<script>" +
            "SELECT * " +
            "FROM teacher " +
            "<where>" +
            "    <if test=\"tid != null\">" +
            " <bind name=\"Key\" value=\"'%'+tid+'%'\"/>" +
            "                        tid like #{Key} " +
            "    </if>" +
            "    <if test=\"tname != null\">" +
            " <bind name=\"Key\" value=\"'%'+tname+'%'\"/>" +
            "                and        tname like #{Key} " +
            "    </if>" +
            "</where>" +
            "LIMIT #{start}, #{size}"+
            "</script>")
    public List<Teacher> get(int start, int size,String tid,String tname);

    @Select("<script>" +
            "SELECT count(*) FROM teacher" +
            "<where>" +
            "    <if test=\"tid != null\">" +
            " <bind name=\"Key\" value=\"'%'+tid+'%'\"/>" +
            "                        tid like #{Key} " +
            "    </if>" +
            "    <if test=\"tname != null\">" +
            " <bind name=\"Key\" value=\"'%'+tname+'%'\"/>" +
            "                and        tname like #{Key} " +
            "    </if>" +
            "</where>" +
            "</script>")
    public int CountTeachers(String tid,String tname);
}
